package com.itheima.sh.controller;

import com.itheima.sh.pojo.User;
import com.itheima.sh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserServiceController {
    @Autowired
    private UserService userService;
    //获取端口号
    @Value("${server.port}")
    private Integer port;
    @GetMapping("user/{username}")
    public User finduser(@PathVariable("username") String username, HttpServletRequest request) {
//        try {
////            Thread.sleep(1000);
////        } catch (InterruptedException e) {
////            e.printStackTrace();
////        }
        //降级演示
//        int i= 1/0;
        String name = request.getHeader("name");
        System.out.println(name);
        System.out.println("port======"+port);
        return userService.finduser(username);
    }
}
